<?php
// +----------------------------------------------------------------------
// | najing [ 通用后台管理系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020 http://www.najingquan.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: lin
// +----------------------------------------------------------------------

namespace  app\admin\controller;

use app\BaseController;
use app\common\model\Manage as ManageModule;
use app\common\model\UserLog;
use think\facade\View;
use think\facade\Session;

/**
 * 登陆管理
 * Class Login
 * @package app\admin\controller
 */
class Login extends  BaseController {

    /**
     * 登陆页
     * @author lin
     */
    public function  login() {
		
		if (Session('?manager')) {
            return redirect(url('Index/index'));
        }

        return View::fetch();
    }

    /**
     * 判断是否登陆
     * @author lin
     */
    public function checkLogin(){

        $manageModel = new ManageModule();
        $result = $manageModel->toLogin(input('param.'));

        if($result['status']){
            $url = url("index/index");

            $datas = [
                'href' =>  $url->build(),
            ];
            return show(0,"",$datas);
        }

        return show(-1,$result['msg'],[]);

    }


    /**
     * 用户退出
     * @author lin
     */
    public function logout()
    {
        //增加退出日志
        if(session('manage.id')){
            $userLogModel = new UserLog();
            $userLogModel->setLog(session('manage.id'),$userLogModel::USER_LOGOUT);
        }
        Session('manage', null);
        return redirect(url('login/login'));
    }





}
